﻿namespace Example.Configuration
{
    using System.Configuration;
    using System.Xml;

    public sealed class CustomConfiguration : IConfigurationSectionHandler
    {
        public static CustomSettings Settings()
        {
            return Settings("example/custom");
        }

        public static CustomSettings Settings(string sectionName)
        {
            return ConfigurationManager.GetSection(sectionName) as CustomSettings;
        }

        public object Create(object parent, 
                             object configContext, 
                             XmlNode section)
        {
            CustomSettings settings = null;

            if (section != null)
            {
                settings = new CustomSettings();
                var node = section.SelectSingleNode("/custom/@setting");
                if (node != null)
                {
                    settings.Setting = node.Value;
                }
            }

            return settings;
        }
    }
}